package io.github.uicdb.liba.api.register;

import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraftforge.registries.RegistryObject;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;

public class MobEffectBuilder<T extends MobEffect> {
    private final LazyRegistry lazyRegistry;
    private final String name;
    private final BiFunction<MobEffectCategory,Integer,T> function;
    private MobEffectCategory category=MobEffectCategory.NEUTRAL;
    private int color=0;
    private final Map<String,String> langMap=new HashMap<>();

    public MobEffectBuilder(LazyRegistry lazyRegistry, String name, BiFunction<MobEffectCategory, Integer,T> function) {
        this.lazyRegistry = lazyRegistry;
        this.name = name;
        this.function = function;
    }
    public MobEffectBuilder<T> color(int color){
        this.color=color;
        return this;
    }
    public MobEffectBuilder<T> category(MobEffectCategory category){
        this.category=category;
        return this;
    }
    public MobEffectBuilder<T> name(String lang,String name){
        langMap.put(lang,name);
        return this;
    }
    public RegistryObject<T> build(){
        var result=lazyRegistry.mobEffects.register(name,()->function.apply(category,color));
        if(!langMap.containsKey(lazyRegistry.defaultLang))name(lazyRegistry.defaultLang, LangBuilder.toTitleCase(name));
        langMap.forEach((lang,name)->{
            lazyRegistry.langMultiMap.put(lang,()->new TranslationBean(result.get().getDescriptionId(),name));
        });
        return result;
    }
}
